package jjn.round2;

import java.util.Arrays;

/**
 * @author Jjn
 * @since 2023/4/29 21:35
 */
public class LeetCode73_SetMatrixZeroes {
    public void setZeroes(int[][] matrix) {
        int height = matrix.length;
        int width = matrix[0].length;
        boolean[] lines = new boolean[height];
        boolean[] rows = new boolean[width];
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                if (matrix[i][j] == 0) {
                    lines[i] = true;
                    rows[j] = true;
                }
            }
        }
        for (int i = 0; i < height; i++) {
            if (lines[i]) {
                Arrays.fill(matrix[i], 0);
            }
        }
        for (int i = 0; i < width; i++) {
            if (rows[i]) {
                for (int j = 0; j < height; j++) {
                    matrix[j][i] = 0;
                }
            }
        }
    }
}
